﻿using Authorization.Center.Controllers;
using Authorization.Center.SqlServer;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using S.Common.helper;
using static S.Weaning.ApI.Application.Command.LambWeaningCommand;

namespace S.Weaning.ApI.Controllers
{
    /// <summary>
    /// 羔羊断奶写
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class LambWeaningController : BaseController
    {
        private readonly IMediator mediator;
        public LambWeaningController(IMediator mediator, MySqlDbContext _db) : base(_db)
        {
            this.mediator = mediator;
        }
        /// <summary>
        ///羔羊断奶新增
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> AddMaternalWeaning(AddLambWeaningCommand command)
        {
            foreach (var item in command.lambweaning)
            {
                item.CreateBy = UserStrategyDto.UserTrueName;
            }
            return Ok(await mediator.Send(command));
        }
        /// <summary>
        /// 羔羊断奶批量删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [Authorize]
        [HttpDelete]
        public async Task<IActionResult> DelLambWeaning(string ids)
        {
            var command = new DelLambWeaningCommand(ids);
            var result = await mediator.Send(command);
            return Ok(result); // 返回修改的记录数或其他相关信息
        }
        /// <summary>
        ///羔羊断奶修改
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> UpdMaternalWeaning(UpdLambWeaningCommand command)
        {
             command.UpdateBy = UserStrategyDto.UserTrueName;
            return Ok(await mediator.Send(command));
        }

    }
}
